﻿#include "StdAfx.h"
#include "text_filter_test.h"

text_filter_test::text_filter_test(void)
{
}

text_filter_test::~text_filter_test(void)
{
}

void text_filter_test::test_constructor()
{
	shared_ptr<text_filter> filter( new text_filter() );
	hash_set<wchar_t> specials = filter->special_characters();
	EXPECT_TRUE( specials.empty() );

	wstring s = L"abcdefg{}+_ 0０－０９－７－０７中文字符";
	filter.reset( new text_filter(s) );
	specials = filter->special_characters();
	for ( hash_set<wchar_t>::const_iterator it = specials.begin(); it != specials.end(); ++it ) {
		wchar_t c = *it;
		EXPECT_TRUE( ( s.find( c ) != wstring::npos ) );
	}
}

void text_filter_test::not_contains()
{
	test_contains( not_string, 0, false );
}
void text_filter_test::non_contains()
{
	test_contains(non_string, 0, true);
}

void text_filter_test::sbc_contains()
{
	test_contains( sbc_string, 0, false );
	test_contains( sbc_string, filter_flags::IGNORE_SBC, true );
}

void text_filter_test::case_contains()
{
	test_contains( case_string, 0, false );
	test_contains( case_string, filter_flags::IGNORE_CASE, true );
}

void text_filter_test::special_contains()
{
	test_contains( special_string, 0, false );
	test_contains( special_string, filter_flags::IGNORE_SPECIAL, true );
}

void text_filter_test::number_contains()
{
	test_contains( number_string, 0, false );
	test_contains( number_string, filter_flags::IGNORE_NUMBER, true );
}

void text_filter_test::non_chinese_contains()
{
	test_contains( non_chinese_string, 0, false );
	test_contains( non_chinese_string, filter_flags::IGNORE_NON_CHINESE, true );
}

void text_filter_test::all_flags_contains()
{
	test_contains( all_string, 0, false );
	int flags = filter_flags::IGNORE_CASE | filter_flags::IGNORE_SBC | filter_flags::IGNORE_SPECIAL | filter_flags::IGNORE_NUMBER;
	test_contains( all_string, flags, true );
}

void text_filter_test::not_replace()
{
	wstring expected = not_string;
	test_replace( not_string, 0, expected );
}

void text_filter_test::non_replace()
{
	wstring expected = L"aBc, 陈凯歌并不是《无极》的唯一***人，一部电影的整体**归电影制片厂所有。";
	test_replace( non_string, 0, expected );
}

void text_filter_test::sbc_replace()
{
	wstring expected = L" ***v";
	test_replace( sbc_string, filter_flags::IGNORE_SBC, expected );
}

void text_filter_test::case_replace()
{
	wstring expected = L" ***V";
	test_replace( case_string, filter_flags::IGNORE_CASE, expected );
}

void text_filter_test::special_replace()
{
	wstring expected = L" *~!@*@#%%$^*v";
	test_replace( special_string, filter_flags::IGNORE_SPECIAL, expected );
}

void text_filter_test::number_replace()
{
	wstring expected = L" 123*123*4653*v";
	test_replace( number_string, filter_flags::IGNORE_NUMBER, expected );
}

void text_filter_test::non_chinese_replace()
{
	wstring expected = L" 中文*оиск в Интер*过@#%$@滤afds字afd符as";
	test_replace( non_chinese_string, filter_flags::IGNORE_NON_CHINESE, expected );
}

void text_filter_test::all_flags_replace()
{
	wstring expected = L" *123*~!#@#$%*as";
	int flags = filter_flags::IGNORE_CASE | filter_flags::IGNORE_SBC 
		| filter_flags::IGNORE_SPECIAL | filter_flags::IGNORE_NUMBER;
	test_replace( all_string, flags, expected );
}

void text_filter_test::test_hits()
{

}
TEST_F( text_filter_test, constructor )
{
	test_constructor();
}
TEST_F( text_filter_test, not_contains )
{
	not_contains();
}

TEST_F( text_filter_test, non_contains )
{
	non_contains();
}

TEST_F( text_filter_test, sbc_contains )
{
	sbc_contains();
}

TEST_F( text_filter_test, case_contains )
{
	case_contains();
}

TEST_F( text_filter_test, special_contains )
{
	special_contains();
}

TEST_F( text_filter_test, number_contains )
{
	number_contains ();
}

TEST_F( text_filter_test, non_chinese_contains )
{
	non_chinese_contains();
}

TEST_F( text_filter_test, all_flags_contains )
{
	all_flags_contains ();
}

TEST_F( text_filter_test, not_replace )
{
	not_replace();
}

TEST_F( text_filter_test, non_replace )
{
	non_replace();
}

TEST_F( text_filter_test, sbc_replace )
{
	sbc_replace();
}

TEST_F( text_filter_test, case_replace )
{
	case_replace();
}

TEST_F( text_filter_test, special_replace )
{
	special_replace();
}

TEST_F( text_filter_test, number_replace )
{
	number_replace ();
}

TEST_F( text_filter_test, non_chinese_replace )
{
	non_chinese_replace();
}

TEST_F( text_filter_test, all_flags_replace )
{
	all_flags_replace ();
}

TEST_F( text_filter_test, hits )
{
	test_hits();
}
